<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/29 0029
 * Time: 11:25
 */
require_once __DIR__ . '/../vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();

$channel->exchange_declare('task_queue', 'fanout',false,true,false);

$channel->queue_declare('task_queue', false, true, false, false);
$channel->queue_bind('task_queue', 'task_queue','task_queue');

$data = implode(' ', array_slice($argv, 1));
if (empty($data)) {
    $data = "Hello World!1111";
}
$msg = new AMQPMessage(
    $data,
    array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)
);

$channel->basic_publish($msg, 'task_queue');

echo ' [x] Sent ', $data, "\n";

$channel->close();
$connection->close();